package tester;
import java.io.IOException;
import java.rmi.RemoteException;

import comunicacao.GestorZooKeeper;
import entities.ConfigInfo;
import entities.Lugar;
import entities.ServerInfo;
import entities.Teatro;
import main.DBmanager;
import main.FileOperator;

/**
 * classe para testes sobre a base de dados
 * 
 * @author Leonardo Lino Nº45340
 * @author Diogo Pires Nº40351
 */
public class DBmanagerTester {

	private static final int ROWS = 20;
	private static final int COLUMNS = 25;
	private static final boolean VERBOSE = false;

	public static void main(String[] args) throws RemoteException, IOException {
		DBmanager database = new DBmanager(new ConfigInfo(), new Object(), new GestorZooKeeper(), new ServerInfo("127.0.0.1",3333, 1), null);/// ISTO NAO DA
		
		
		//getTheaterTester(database, "teatro2", VERBOSE);
		//reserveSeatTester(database, "teatro2", 25258, 5, "10500",true);
		//purchaseSeatTester(database, "teatro2", 25259, 5, true);
		//removeSeatReserveTester(database, "teatro2", 25258, 5, true);
		//failureTester(database);
		//getTheaterTester(database,"teatro2",VERBOSE);
	}

	public static void failureTester(DBmanager database) throws RemoteException {
		database.falha(true,false);
		System.out.println("Esta em falha?: "+database.isInFailure());
	}
	
	public static void restartTester(DBmanager database) throws RemoteException {
		database.restart();
		System.out.println("Esta em falha?: "+database.isInFailure());
	}
	
	/*public static void getTheaterTester(DBmanager db, String nome,
			boolean verbose) throws IOException {
		Teatro teatro = db.getTheater(nome);

		if (verbose) {
			int i = 0;

			System.out.println("ID: " + teatro.id);
			System.out.println("Nome: " + teatro.nome);
			System.out.println("Total de Lugares: " + teatro.lugaresTotal);
			System.out.println("Lugares Ocupados: " + teatro.lugaresOcupados);
			System.out.println("Lugares Reservados: " + teatro.lugaresReservados
					+ "\n");
			for (Lugar seat : teatro.lugares) {
				i++;
				System.out.print("ID:" + seat.id + " ");
				System.out.print("Line:" + seat.row + " ");
				System.out.print("Col:" + seat.column + " ");
				System.out.print("State:" + seat.state + " ");
				
				if(seat.state == Lugar.STATE_FREE)
					System.out.println();
				if(seat.state == Lugar.STATE_BOUGHT)
					System.out.println("UserID: " + seat.getUserID());
				if(seat.state == Lugar.STATE_RESERVED){
					System.out.print("UserID: " + seat.getUserID() + " ");
					System.out.println("Timestamp: " + seat.getTimestamp());
				}
				
			}
			System.out.println(i);
		}
	}*/

	public static void listTheatersTester(DBmanager db,
			boolean verbose) throws IOException {

		if (verbose)
			System.out.println(db.listTheaters());
		else
			db.listTheaters();
	}

	public static void reserveSeatTester(DBmanager db, String name, int userID, int lugarID,
			String timestamp, boolean verbose) throws IOException {

		if (verbose)
			System.out.println(db.reserveSeat(name, lugarID, userID, timestamp, false));
		else
			db.reserveSeat(name, lugarID, userID, timestamp, false);
	}
	
	public static void removeSeatReserveTester(DBmanager db, String name, int userID, int lugarID,
			boolean verbose) throws IOException {

		if (verbose)
			System.out.println(db.removeSeatReserve(name, lugarID, userID, false));
		else
			db.removeSeatReserve(name, lugarID, userID, false);
	}

	public static void purchaseSeatTester(DBmanager db, String name, int userID, int lugarID,
			boolean verbose) throws IOException {

		if (verbose)
			System.out.println(db.purchaseSeat(name, lugarID, userID, false));
		else
			db.purchaseSeat(name, lugarID, userID, false);
	}
	
}
